<?php require_once('../../Connections/cotiza.php'); ?>
<?php
$maquina   = $_GET['maquina'];
$solicitud = $_GET['solicitud'];
$proc      = $_GET['proc'];
$origen    = $_GET['origen'];
$val       = $_GET['val'];
$vel	   = $_GET['vel'];
$ren	   = $_GET['ren'];
$fin       = $_GET['fin'];

$query = "SELECT mach_velocidad as vel FROM mach_mstr WHERE mach_proc = $proc AND mach_id = '$maquina'";

//echo "consulta = ".$query;
$rslt_vel = mysql_query($query,$cotiza) or die(mysql_error());
$row_vel  = mysql_fetch_assoc($rslt_vel);

if($row_vel['vel'] == "")
	$vel  = 0;
else
	$vel  = $row_vel['vel'];

if($origen == "maq")
{
	$query    = "INSERT INTO mach_det (mach_proc_id, mach_solic_id, mach_id, mach_velocidad) 
			            VALUES ($proc,'$solicitud','$maquina',$vel)
 ON DUPLICATE KEY UPDATE mach_id = '$maquina', mach_velocidad = $vel, mach_rendimiento = NULL, mach_vel_fin = NULL";
} //if($origen == "maq")

if($origen == "vel" || $origen == "ren" || $origen == "fin")
{
	$query = "UPDATE mach_det SET mach_velocidad = '$vel', mach_rendimiento = '$ren', mach_vel_fin = '$fin'
	           WHERE mach_id = '$maquina' AND mach_solic_id = '$solicitud'";
}

echo $query;
mysql_query($query,$cotiza) or die(mysql_error());
?>